/**
 * fileName:  ArgumentImpl.java
 * author:  Pitaya
 * Company:  Cloudland Studio
 * Createdate:  2014-6-7 上午12:44:26
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-7            Pitaya            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.handler.support;

import java.util.ArrayList;
import java.util.List;

import org.cloudland.commercial.masterdata.bean.ArgumentInfo;
import org.cloudland.commercial.masterdata.handler.ArgumentStore;
import org.cloudland.commercial.masterdata.store.PageResult;
import org.cloudland.commercial.masterdata.store.entity.ArgumentEntity;
import org.cloudland.commercial.masterdata.store.entity.PageQueryEntity;
import org.cloudland.commercial.masterdata.store.read.ArgumentReader;
import org.cloudland.commercial.masterdata.store.write.ArgumentWriter;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  ArgumentImpl
 * @author  Pitaya
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class ArgumentImpl implements ArgumentStore {

	private ArgumentReader argReader;
	
	private ArgumentWriter argWriter;
	
	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *
	 * @param argReader
	 * @param argWriter   
	 */
	public ArgumentImpl(ArgumentWriter argWriter, ArgumentReader argReader) {
		this.argWriter = argWriter;
		this.argReader = argReader;
	}

	/**
	 * @return
	 */
	public ArgumentInfo createFruitArgument() {
		return new ArgumentBean(argWriter);
	}

	/**
	 * @param argumentId
	 * @return
	 */
	public ArgumentInfo queryFruitArgumentById(String argumentId) {
		ArgumentEntity argEntity = argReader.findArgumentById(argumentId);
		return new ArgumentBean(argEntity, argWriter);
	}

	/**
	 * @return
	 */
	public List<ArgumentInfo> queryFruitArgumentAll() 
	{
		List<ArgumentEntity> arrList = argReader.getFruitArgumentAll();
		List<ArgumentInfo> resultList = new ArrayList<ArgumentInfo>(arrList.size()); 
		
		for(ArgumentEntity entity : arrList)
		{
			resultList.add(new ArgumentBean(entity,argWriter));
		}
		return resultList;
	}

	/**
	 * @param argumentId
	 * @return
	 */
	public Boolean delFruitArgument(String argumentId) 
	{
		ArgumentEntity entity = new ArgumentEntity(argumentId,"","",1);
		boolean flag = argWriter.delArgumentInfo(entity);
		return flag;
	}

	/**
	 * @param startNo
	 * @param pageSize
	 * @return
	 */
	public PageResult<ArgumentInfo> findPageArgumentInfo(Integer startNo, Integer pageSize) {
		PageQueryEntity<ArgumentEntity> result = argReader.findArgumentForPage(startNo, pageSize);
		PageQueryEntity<ArgumentInfo> pageResult = new PageQueryEntity<ArgumentInfo>(result.count(), new ArrayList<ArgumentInfo>());
		
		for(ArgumentEntity entity : result.list())
		{
			pageResult.list().add(new ArgumentBean(entity,argWriter));
		}
		return pageResult;
	}

	/**
	 * @param name
	 * @param startNo
	 * @param pageSize
	 * @return
	 */
	public PageResult<ArgumentInfo> findArgumentInfoByName(String name, Integer startNo, Integer pageSize) {
		PageQueryEntity<ArgumentEntity> result = argReader.findArgumentByName(name, startNo, pageSize);
		PageQueryEntity<ArgumentInfo> pageResult = new PageQueryEntity<ArgumentInfo>(result.count(), new ArrayList<ArgumentInfo>());
		
		for(ArgumentEntity entity : result.list())
		{
			pageResult.list().add(new ArgumentBean(entity,argWriter));
		}
		return pageResult;
	}
	
}
